// pages/memberList/memberList.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show:null,
    showApp:false,
    list: [],
    search: {
      pageNumber: 1,
      pageSize: 10,
      totalPages: 0,
      orgId: '',
      name: ''
    },
    req:false
  },
  detail: function(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/pages/myCardNew/myCardNew?type=visitor&id=' + id+'&name='+name,
    })
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  toPage(e) {
    var dataset = e.currentTarget.dataset;
    var url = dataset.turn + '?id='+ dataset.id
    wx.navigateTo({
      url: url
    })
  },
  show(e) {
    console.log('点击',e.currentTarget.dataset)
    var dataset = e.currentTarget.dataset;
    this.toggle("show", dataset.index)
    console.log('点击1', this.data.show)
  },
  hide() {
    this.toggle("show", null)
  },
  check: function () {
    this.toggle("showApp", true);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    this.toggle("search.orgId", options.id); 
    this.toggle("orgType", options.type ? options.type:''); 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  onSearch: function(e) {
    var value = e.detail.value;
    this.refreshList(value);
  },
  refreshList: function(name) {
    this.toggle("search.pageNumber", 1);
    this.toggle("search.totalPages", 0);
    this.toggle("search.name", name || '');
    this.list();
  },
  list: function(append) {
    var that = this;
    that.toggle('req',false)
    app.req({
      // url: "orgmini/manager/getOrgUserPage",
      url:"orgmini/org/newOrgUserPage",
      data: that.data.search,
      success: function(res) {
        if (200 == res.code) {
          var oriList = that.data.list;
          var newList = res.data.page.rows;
          that.toggle("list", append ? oriList.concat(newList) : newList);
          that.toggle("search.totalPages", res.data.page.totalPages);
          that.toggle("userlist", res.data.user);
          that.toggle('req', true)
        }
      }
    });
  },
  getandpost(){
    var that = this
    app.req({
      url: "orgmini/org/newGetStructureAndPost",
      data: {
        orgId: that.data.search.orgId
      },
      success: function (res) {
        if (200 == res.code) {
             console.log('部门',res.data)
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    app.getUserInfo(function(userInfo) {
      that.refreshList();
      that.toggle('realName', userInfo.realName)
      that.toggle('nickName', userInfo.nickName)
    });
    that.getandpost()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    app.getUserInfo(function(userInfo) {
      that.refreshList();
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    var search = that.data.search;
    if (search.totalPages > search.pageNumber) {
      that.toggle("search.pageNumber", search.pageNumber + 1);
      that.list(true);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})